﻿@model List<VersionLibModel>
@{
    ViewBag.Title = "欢迎进入后台管理";
    Layout = "~/Views/Shared/_BackStageLayout.cshtml";
}
<div id="content" class="content">
    <!-- begin breadcrumb -->
    <ol class="breadcrumb pull-right">
        <li><a href="javascript:;">用户列表</a></li>
    </ol>
    <!-- end breadcrumb -->
    <!-- begin page-header -->
    <!-- end page-header -->
    <!-- begin row -->
    <div class="row">
        <!-- begin col-12 -->
        <div class="col-md-12">
            <!-- begin panel -->
            <div class="panel panel-inverse">
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="data-table" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>简称</th>
                                    <th>项目名</th>
                                    <th>当前版本</th>
                                    <th>更新时间</th>
                                    <th>项目描述</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var data in Model)
                                {
                                    <tr class="odd ">
                                        <td>@data.ShortName</td>
                                        <td>@data.ProjectName</td>
                                        <td>@data.LatestVersion</td>
                                        <td>@data.UpdateTime.ToString("yyyy-MM-dd HH:mm")</td>
                                        <td>@data.Description</td>
                                        <td><button type="button" class="btn btn-primary btn-xs m-r-5 m-b-5" onclick="ShowDetail('@data.Id')">查看详细</button>
                                            <button type="button" class="btn btn-warning btn-xs m-r-5 m-b-5" onclick="Update('@data.Id')">修改</button>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                        <div class="data-table_filter">
                            <div class="input-group input-daterange col-md-4" style="padding-left: 1%;" data-date-format="yyyy-mm-dd">
                                <a href="javascript:;" class="btn btn-danger btn-sm m-r-5 m-b-5 " id="add" >添加版本库</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- end panel -->
        </div>
        <!-- end col-12 -->
    </div>
    <!-- end row -->
</div>

<div class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title">添加版本库</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal form-bordered">
                    <div class="form-group">
                        <label class="control-label col-md-4">简称</label>
                        <div class="col-md-8">
                            <input type="text" value="" class="form-control" id="shortName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-4">项目名</label>
                        <div class="col-md-8">
                            <input type="text" value="" class="form-control" id="projectName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-4">项目描述</label>
                        <div class="col-md-8">
                            <textarea class="form-control" placeholder="项目描述" rows="5" id="description"></textarea>
                        </div>
                    </div>
                </form>
            </div>
       
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
@section footer {
    <script>
        var versionId = "";
        $(document).ready(function () {
            App.init();
            TableManageDefault.init();
            $("#save").click(function () {
                var shortName=$("#shortName").val();
                var projectName=$("#projectName").val();
                var description=$("#description").val();
                client.api.updateVersionLib({
                    "Id": versionId, "ShortName": shortName, "ProjectName": projectName,
                    "Description": description
                },
                    function (data) {
                        if (data.ReCode != "1000") {
                        alert(data.ReMsg);
                        } else
                        {
                            $(".modal").hide();
                        }
            },
            function (data) {
            });
            });

            $("#add").click(function () {
                versionId = "";
                $(".modal-title").text("添加");
                $(".modal").modal();
                $("#shortName").val("");
                $("#projectName").val("");
                $("#description").val("");
            });

        });

        function ShowDetail(shortName)
        {
            window.location.href = "@Url.Action("VersionList","BackStage")?shortName=" + shortName;
        }

        function Add()
        {

        }

        function Update(id)
        {
            versionId = id;
            client.api.getVersionLib({ "id": id },
            function (data) {
                if (data.ReCode != "1000") {
                    alert(data.ReMsg);
                } else {
                    $(".modal-title").text("信息修改");
                    $(".modal").modal();
                    $("#shortName").val(data.ReData.ShortName);
                    $("#projectName").val(data.ReData.ProjectName);
                    $("#description").val(data.ReData.Description);
                }},function (data) {
                    });
        }

    </script>
}
